<?php

namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Exceptions\HttpResponseException;

class Authenticate extends Middleware
{
    /**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return string
     */
    protected function redirectTo($request)
    {
        $request->headers->set('Accept', 'application/json');
        throw (new HttpResponseException(response()->json([
            'code' => 0,
            'message' => '未登录！',
            'data' => '验证未通过'
        ])->setStatusCode(401)));
    }
}
